<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>04清除画布</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    canvas {
      border: 1px solid #000;
    }
  </style>
</head>
<body>
<!--canvas的高度和宽度务必使用行内样式设置-->
<canvas height="400px" width="600px">

</canvas>
</body>
</html>

<script>
  // 获取canvas元素
  let canvas = document.querySelector('canvas');
  // 获取绘图上下文
  let ctx = canvas.getContext('2d');
  ctx.fillRect(0, 0, 100, 400); // 绘制矩形
  ctx.clearRect(50, 50, 50, 50); // 清除矩形

</script>
